/**
 */
"use strict"

var Router = require('koa-router');
var config = require('../../../config/config.js');

console.log('router:' + config.baseUrl + '/v1');

var router = new Router({
    prefix: config.baseUrl + '/v1'
});

/**
 * all router
 */
router.post('/**', function*(next) {
    // console.log('global router post');

    var inParams;
    if (typeof this.request.body === 'string') {
        try {
            inParams = JSON.parse(this.request.body);
        } catch (e) {
            this.body = 'error : input must be json';
            return;
        }
    } else {
        inParams = this.request.body;
    }

    this.request.inParams = inParams;
    yield next;
});

router.get('/**', function*(next) {
    // console.log('global router get');
    this.request.inParams = this.request.query;
    yield next;
});


module.exports = router.routes();